from flask import render_template, url_for, request, session, redirect
# from sqlconfig import db, User, app
from config import app, db, User


# app = Flask(__name__)

# 创建数据表
# db.create_all()
# 添加数据
# user = User(username='123', password='456')
# db.session.add(user)
# db.session.commit()


@app.route('/')
def index():
    return render_template('index/index.html', url=url_for('index'))


# @app.route('/index/')
# def index1():
#     return render_template('index/index.html',url = url_for('index'))


@app.route('/about/')
def about():
    # 添加数据
    # user = User(username='123', password='456')
    # db.session.add(user)
    # db.session.commit()
    return render_template('index/about.html', url=url_for('about'))


@app.route('/causes/')
def causes():
    return render_template('index/causes.html', url=url_for('causes'))


@app.route('/portfolio/')
def portfolio():
    return render_template('index/portfolio.html', url=url_for('portfolio'))


@app.route('/news/')
def news():
    return render_template('index/news.html', url=url_for('news'))


@app.route('/contact/')
def contact():
    return render_template('index/contact.html', url=url_for('contact'))


@app.route('/elements/')
def elements():
    return render_template('index/elements.html', url=url_for('elements'))


@app.route('/single_causes/')
def single_causes():
    return render_template('index/single-causes.html', url=url_for('single_causes'))


# 登录页
# @app.route('/login/')
# def login():
#     return render_template('index/login.html')

@app.route('/login/',methods=['GET','POST'])
def login():
    if request.method == 'GET':
        return render_template('index/login.html',session = session.get('user'))
    if request.method == 'POST':
        if request.form.get('username') == 'anwen':
            session['user'] = request.form.get('username')
            session.permanent = True
            return render_template('index/login.html',session = session['user'])
            # return redirect('/',session = session['user'])

# 注册页
@app.route('/register/')
def register():
    return render_template('index/register.html')


# 忘记密码
@app.route('/forgot-password/')
def forgot_password():
    return render_template('index/forgot-password.html')


@app.route('/test')
def test():
    return render_template('test/index.html')


if __name__ == '__main__':
    app.run()
